package com.haiyou.dc.thread.test3;

public class HappenBefore {

    private  static int a = 0;
    private  static boolean flag = false;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 100; i++) {
            a = 0;
            flag = false;
            System.out.println("------------->fori=" + i);
            //修改数据
            Thread t1 = new Thread(() -> {
                a = 1;
                flag = true;
            });

            Thread t2 = new Thread(() -> {
                if (flag) {
                    a *= 1;
                }
                if (a == 0) {
                    System.out.println("--------->" + a);
                }
            });
            t1.start();
            t2.start();

            t1.join();
            t2.join();
        }
    }
}
